package com.financial.common.vo;

import com.financial.common.constants.ResultCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@ApiModel(value = "全局统一返回结果")
public class ResponseResult {

    @ApiModelProperty(value = "是否成功")
    private Boolean success;
    @ApiModelProperty(value = "返回码")
    private Integer code;
    @ApiModelProperty(value = "返回消息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private Object result ;


    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    private ResponseResult(){}
    public static ResponseResult ok(){
        ResponseResult r = new ResponseResult();
        r.setSuccess(ResultCodeEnum.SUCCESS.getSuccess());
        r.setCode(ResultCodeEnum.SUCCESS.getCode());
        r.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        return r;
    }
    public static ResponseResult error(){
        ResponseResult r = new ResponseResult();
        r.setSuccess(ResultCodeEnum.UNKNOWN_REASON.getSuccess());
        r.setCode(ResultCodeEnum.UNKNOWN_REASON.getCode());
        r.setMessage(ResultCodeEnum.UNKNOWN_REASON.getMessage());
        return r;
    }
    public static ResponseResult setResult(ResultCodeEnum resultCodeEnum){
        ResponseResult r = new ResponseResult();
        r.setSuccess(resultCodeEnum.getSuccess());
        r.setCode(resultCodeEnum.getCode());
        r.setMessage(resultCodeEnum.getMessage());
        return r;
    }
    public ResponseResult success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public ResponseResult message(String message){
        this.setMessage(message);
        return this;
    }
    public ResponseResult code(Integer code){
        this.setCode(code);
        return this;
    }

    public ResponseResult result(String key, Object value){
        Map<String,Object> map = new HashMap();
        map.put(key, value);
        this.result = map;
        return this;
    }

    public ResponseResult result(Map<String, Object> map){
        this.setResult(map);
        return this;
    }

    /**
     *  用户处理年限
     * @param list
     * @return
     */
    public ResponseResult result(List<String> list){
        this.result = list;
        return this;
    }

    /**
     *  单个对象返回
     * @param obj
     * @return
     */
    public ResponseResult result(Object obj){
        this.result = obj;
        return this;
    }

    public ResponseResult result(Object baselist,Object allPage,Object allCount,Object nowPage,Object pageSize){
        Map<String,Object> map = new HashMap();
        map.put("datalist", baselist);
        map.put("allPage", allPage);
        map.put("allCount", allCount);
        map.put("nowPage", nowPage);
        map.put("pageSize", pageSize);
        this.result = map;
        return this;
    }
}
